<?php
/**
 * 忘记密码
 * User: tengyu
 * Date: 2017/8/29
 * Time: 14:33
 */?>
@extends('common.common')
@section('title','忘记密码')
@section('css')<link rel="stylesheet" href="{{asset('/css/forgot_pwd.css')}}">@endsection
@section('content')
    <div id="content">
        <div class="container">
            <div class="loginBox">
                <p class="register"><h3>找回密码</h3></p>
                @if (count($errors) > 0)
                    <div class="alert alert-danger text-left">
                        <strong>验证信息有误!</strong>
                        <ul>
                            @if(is_object($errors))
                                @foreach ($errors->all() as $error)
                                    <li>{{ $error }}</li>
                                @endforeach
                            @else
                                <li>{{$errors}}</li>
                            @endif
                        </ul>
                    </div>
                @endif
                <!--表单-->
                <form class="form-horizontal" action="{{url('/resetpw')}}" method="post" onsubmit="return resetpw_form()">
                    {!! csrf_field() !!}
                    <div class="form-group loginperson">
                        <input class="form-control" type="text" name="phone" value="{{old('phone')}}" placeholder="+86手机号">
                        <b></b>
                    </div>
                    <!--短信验证码-->
                    <div class="form-group message">
                        <input class="form-control" type="text" name="mscode" value="" placeholder="请输入短信验证码">
                        <b></b>
                        <button id="forgetpw_send" class="btn-default btn lf send" onclick="mscode_resetpw()" style="margin-left: 24px;width: 100px;">点击发送</button>
                    </div>
                    <div class="form-group">
                        <input class="btn btn-warning btn-block" type="submit" value="密码重置">
                    </div>
                </form>
            </div>
        </div>
    </div>
    <script>
        /**密码重置信息基础校验*/
        function resetpw_form()
        {
            /**手机校验*/
            var phone = $("input[name='phone']").val();
            if(!phone){
                $("input[name='phone']").focus();return false;
            }
            /**短信验证码空校验*/
            var mscode = $("input[name='mscode']").val();
            if(!mscode){
                $("input[name='mscode']").focus();return false;
            }

            if(!(/^1[3|4|5|7|8][0-9]\d{8}$/.test(phone))) {
                alert('请先输入正确手机号!');
                $("input[name='phone']").focus();return false;
            }
            return true;
        }

        var count=60;
        /**手机校验发送*/
        function mscode_resetpw()
        {
            $("#forgetpw_send").attr("disabled",true)
            var phone = $("input[name='phone']").val();
            curCount = count;
            InterValObj = window.setInterval(SetRemainTime, 1000);
            /**防止重复发送*/
            $.ajax({
                url:'/mscode',
                type:'post',
                data: {'phone':phone,'type':2},
                headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' },
                dataType: "json",
                success:function(res){
                    if(res.msg=='ok'){
                        console.log('发送成功');
                    }else{
                        console.log(res);
                    }
                }
            });
        }

        /**时间处理*/
        function SetRemainTime() {
            if (curCount != 0) {
                curCount--;
                $("#forgetpw_send").text(curCount + "秒");
            }else{
                window.clearInterval(InterValObj);//停止计时器
                $("#forgetpw_send").removeAttr("disabled");//启用按钮
                $("#forgetpw_send").text("重新发送");
            }
        }
    </script>
@endsection
